package com.readbook.action;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.readbook.service.WechartService;
import com.readbook.util.*;
import net.sf.jxls.exception.ParsePropertyException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/wechart")
public class wechart {
    @Resource
    private WechartService wechartService;

    /**
     * @author 牟明艳
     * @comments 成功获取到openid并进入连接开始业务处理
     * @time 2015-11-17 下午3:07:15
     */
    @RequestMapping("getwxuserinfo.html")
    public @ResponseBody
    Map<String, Object> getwxuserinfo(HttpServletRequest req) {
        String code = req.getParameter("code");
        //第二步:通过code获取access_token
        ConfKit confkit= new ConfKit("wxpay.properties");
		String urlwx = "https://api.weixin.qq.com/sns/jscode2session?appid="+confkit.get("appid")+"&secret="+confkit.get("appsecret")+"&js_code="+code+"&grant_type=authorization_code";
       //String urlwx = "https://api.weixin.qq.com/sns/jscode2session?appid=" + tappid + "&secret=" + tappsecret + "&js_code=" + code + "&grant_type=authorization_code";
        String access_token_json = HttpClientUtil.sendGet(urlwx);
        Map<String, String> p_access_token = JSON.parseObject(access_token_json, HashMap.class);

        Map<String, Object> setmap = new HashMap<String, Object>();
        String openid = "";
        if (p_access_token.get("openid") != null) {
            openid = p_access_token.get("openid").toString();
            Map<String, Object> wxmap = new HashMap<String, Object>();
            wxmap.put("wxid", openid);
            //查询是否已经绑定了账号和密码
            List<Map<String, Object>> list1 = wechartService.getuserBindStu(wxmap);
            if (list1.size() > 1) {
                setmap.put("user_type", 1);
                setmap.put("stusize", list1.size());

                List<Map<String, Object>> listmaps = new ArrayList<>();
                for (int m = 0; m < list1.size(); m++) {
                    Map<String, Object> bzh = list1.get(m);
                    Map<String, Object> struformap = new HashMap<>();
                    struformap.put("name", bzh.get("NAME"));
                    struformap.put("sex", bzh.get("SEX"));
                    struformap.put("identity", bzh.get("ZW"));
                    struformap.put("user_type", bzh.get("WSTATE"));
                    struformap.put("nj", bzh.get("NJ"));
                    struformap.put("bj", bzh.get("BJ"));
                    struformap.put("phone", bzh.get("PHONE"));
                    struformap.put("usid", bzh.get("USID"));
                    struformap.put("dlzh", bzh.get("DLZH"));
                    listmaps.add(struformap);
                }
                setmap.put("stus", listmaps);
            } else if (list1.size() == 1) {
                Map<String, Object> bzh = list1.get(0);
                if (bzh.get("DLZH") != null && bzh.get("DLMA") != null) {
                    // setmap=wechartService.getUserInfoThird(bzh.get("DLZH").toString(),bzh.get("DLMA").toString());
                    setmap.put("name", bzh.get("NAME"));
                    setmap.put("sex", bzh.get("SEX"));
                    setmap.put("identity", bzh.get("ZW"));
                    setmap.put("user_type", bzh.get("WSTATE"));
                    setmap.put("nj", bzh.get("NJ"));
                    setmap.put("bj", bzh.get("BJ"));
                    setmap.put("phone", bzh.get("PHONE"));
                    setmap.put("usid", bzh.get("USID"));
                    setmap.put("dlzh", bzh.get("DLZH"));
                }
            }
        }
        String session_key = p_access_token.get("session_key").toString();
        setmap.put("openid", openid);
        setmap.put("session_key", session_key);
        return setmap;
    }




    /**
     * @author 牟明艳
     * @comments 购买 提交订单
     * @time 2017年12月15日10:39:37
     */
    @RequestMapping("submitorder.html")
    public @ResponseBody
    Map<String, Object> submitorder(HttpServletRequest req) {
        String orderid = req.getParameter("oid");
        String wxid = req.getParameter("wxid");
        String ordername = req.getParameter("ordername");


        //手续费 总金额的百分几
        String allprice = req.getParameter("allprice");//总价格
        String fs3 = req.getParameter("fs3");//手续费占百分几
        float f1 = Float.parseFloat(allprice) * Float.parseFloat(fs3);
        double f2 = f1 * 0.01;
        double zje = Double.parseDouble(allprice) + f2;
        DecimalFormat zhje = new DecimalFormat(".00");
        String zjg = zhje.format(zje);


        String ip = req.getHeader("X-Forwarded-For");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = req.getRemoteAddr();
        }

        //支付
        Map<String, Object> paymap = new HashMap<String, Object>();
        long timeStamp_ = System.currentTimeMillis();   //时间戳
        String payurl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        String timeStamp = String.valueOf(timeStamp_);

        //金额转换
        float floatmonye = Float.parseFloat(zjg) * 100;
        int Moneys = (int) floatmonye;
        SortedMap<String, Object> treeMap = new TreeMap<String, Object>();

        String nonce_str = PayCommonUtil.CreateNoncestr();
        ConfKit confkit = new ConfKit("wxpay.properties");
        treeMap.put("appid", confkit.get("appid"));// 微信分配的小程序ID
        treeMap.put("body", "柒彩教育-" + ordername);  //商品简单描述  商家名称-销售商品类目
        treeMap.put("detail", "柒彩教育-" + ordername);  //单品优惠字段v
        treeMap.put("mch_id", confkit.get("mch_id")); //微信支付分配的商户号
        treeMap.put("nonce_str", nonce_str); //随机字符串，不长于32位。
        treeMap.put("notify_url", confkit.get("notify_url") + "/wechart/notify.html");  //接收微信支付异步通知回调地址
        treeMap.put("openid", wxid); //用户在商户appid下的唯一标识。openid如何获取
        treeMap.put("out_trade_no", orderid);  //商户系统内部的订单号
        treeMap.put("spbill_create_ip", ip);
        treeMap.put("total_fee", Moneys + "");  //订单总金额，单位为分
        treeMap.put("trade_type", "JSAPI"); //交易类型
        String sign = PayCommonUtil.createSign(treeMap, confkit);//生成签名的方法
        treeMap.put("sign", sign);  //签名

        String xmltreemap = "<xml>" +
                "<appid>" + confkit.get("appid") + "</appid>" +
                "<body>柒彩教育-" + ordername + "</body>" +
                "<detail>柒彩教育-" + ordername + "</detail>" +
                "<mch_id>" + confkit.get("mch_id") + "</mch_id>" +
                "<nonce_str>" + nonce_str + "</nonce_str>" +
                "<notify_url>" + confkit.get("notify_url") + "/wechart/notify.html" + "</notify_url>" +
                "<openid>" + wxid + "</openid>" +
                "<out_trade_no>" + orderid + "</out_trade_no>" +
                "<spbill_create_ip>" + ip + "</spbill_create_ip>" +
                "<total_fee>" + Moneys + "" + "</total_fee>" +
                "<trade_type>JSAPI</trade_type>" +
                "<sign>" + sign + "</sign>" +
                "</xml>";
        String prepay_id = GetWxOrderno.getPayNo(payurl, xmltreemap);

        //再次签名
        String sb = "appId=" + confkit.get("appid") + "&";
        sb += "nonceStr=" + nonce_str + "&";
        sb += "package=prepay_id=" + prepay_id + "&";
        sb += "signType=MD5&timeStamp=" + timeStamp + "&";
        sb += "key=" + confkit.get("key");

        String paysign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
        paymap.put("timeStamp", timeStamp);
        paymap.put("nonceStr", nonce_str);
        paymap.put("prepay_id", prepay_id);
        paymap.put("sign", paysign);
        paymap.put("orderid", orderid);

        System.out.println("paymap:" + paymap);
        return paymap;
    }

    /**
     * @author 牟明艳
     * @comments 添加购物车
     * @time 2017年10月25日18:50:05
     */
    @RequestMapping("notify.html")
    public @ResponseBody
    void notify(HttpServletRequest req) {
        System.out.print("微信支付回调数据开始");
        //示例报文
        String inputLine;
        String notityXml = "";
        String resXml = "";
        try {
            while ((inputLine = req.getReader().readLine()) != null) {
                notityXml += inputLine;
            }
            req.getReader().close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println("接收到的报文：" + notityXml);

        System.out.println("微信支付回调数据结束");
        return;
    }


    /*
     * 上传图片
     */
    @RequestMapping("uploadBmurl.html")
    public @ResponseBody
    Map<String, Object> uploadBmurl(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> param = new HashMap<String, Object>();
        MultipartHttpServletRequest mhsr = (MultipartHttpServletRequest) request;
        if (mhsr == null) {
            return param;
        }
        DiskFileItemFactory fac = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(fac);
        upload.setHeaderEncoding("utf-8");
        try {
            mhsr.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        String se = File.separator;
        String savePath = mhsr.getRealPath("upload") + se + "bmqk";
        File f1 = new File(savePath);
        if (!f1.exists()) {
            f1.mkdirs();
        }
        String strfile = "";
        try {
            Map<String, MultipartFile> files = mhsr.getFileMap();
            for (String key : files.keySet()) {
                MultipartFile mf = mhsr.getFile(key);
                String name = mf.getOriginalFilename();
                String extName = "";
                if ((name != null) && (!name.trim().equals(""))) {
                    if (name.lastIndexOf(".") >= 0) {
                        extName = name.substring(name.lastIndexOf("."));
                    }
                    Long fname = Long.valueOf(System.nanoTime());
                    File file = new File(savePath + se + fname + extName);
                    if (!file.exists()) {
                        file.createNewFile();
                    }
                    mf.transferTo(file);
                    strfile = "upload\\//bmqk" + "\\//" + fname + extName;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        param.put("urls", strfile);
        return param;
    }

    /**
     * @author 牟明艳
     * @comments 微信登录
     * @time 2019年8月16日14:08:40
     */
    @RequestMapping("wechartlogin.html")
    public @ResponseBody
    Map<String, Object> wechartlogin(HttpServletRequest req) {
        Map<String, Object> remap = new HashMap<String, Object>();
        String dlzh = req.getParameter("dlzh");
        String dlma = req.getParameter("dlma");
        String wxid = req.getParameter("wxid");
        remap = wechartService.getUserInfoThird(dlzh, dlma);

        if (remap.get("name") != null) {
            Map<String, Object> semap = new HashMap<String, Object>();
            //根据登录账号查询是否已经有生成的usid
            Map<String, Object> zhmap = new HashMap<String, Object>();
            zhmap.put("dlzh", dlzh);
            List<Map<String, Object>> list1 = new ArrayList<>();
            list1 = wechartService.getUsidBydlzh(zhmap);
            String usid = "";
            if (list1.size() > 0) {
                usid = list1.get(0).get("USID").toString();
            } else {
                usid = UUID.randomUUID().toString().replaceAll("-", "");
            }
            remap.put("usid", usid);
            semap.put("wxid", wxid);
            semap.put("usid", usid);
            semap.put("name", remap.get("name"));
            semap.put("nj", remap.get("nj"));
            semap.put("bj", remap.get("bj"));
            semap.put("zw", remap.get("identity"));
            semap.put("wstate", remap.get("user_type"));//1学生 2教师
            semap.put("dlzh", dlzh);
            semap.put("dlma", dlma);
            semap.put("phone", remap.get("phone"));
            semap.put("sex", remap.get("sex"));
            wechartService.insertwxbangding(semap);
        } else if (remap.get("stus") != null) {
            String stus = remap.get("stus").toString();
            List<Map<String, Object>> listr = (List<Map<String, Object>>) JSONArray.parse(stus);
            List<Map<String, Object>> listus = new ArrayList<>();
            for (int i = 0; i < listr.size(); i++) {
                Map<String, Object> maps1 = listr.get(i);
                Map<String, Object> zhmap = new HashMap<String, Object>();
                zhmap.put("name", maps1.get("name"));
                zhmap.put("nj", maps1.get("nj"));
                zhmap.put("bj", maps1.get("bj"));
                zhmap.put("dlzh", dlzh);
                List<Map<String, Object>> list1 = new ArrayList<>();
                list1 = wechartService.getUsidBydlzh(zhmap);
                String usid = "";
                if (list1.size() > 0) {
                    usid = list1.get(0).get("USID").toString();
                } else {
                    usid = UUID.randomUUID().toString().replaceAll("-", "");
                }
                remap.put("usid", usid);
                Map<String, Object> semap = new HashMap<String, Object>();
                semap.put("wxid", wxid);
                semap.put("usid", usid);
                semap.put("name", maps1.get("name"));
                semap.put("nj", maps1.get("nj"));
                semap.put("bj", maps1.get("bj"));
                semap.put("zw", maps1.get("identity"));
                semap.put("wstate", maps1.get("user_type"));//1学生 2教师
                semap.put("dlzh", dlzh);
                semap.put("dlma", dlma);
                semap.put("phone", maps1.get("phone"));
                semap.put("sex", maps1.get("sex"));
                wechartService.insertwxbangding(semap);
                listus.add(semap);
            }
            remap.put("stus", listus);
        }
        return remap;
    }











    /**
     * @author 牟明艳
     * @comments 成功获取到openid并进入连接开始业务处理
     * @time 2019年11月22日17:25:59
     */
    @RequestMapping("getwxandinguserinfo.html")
    public @ResponseBody
    Map<String, Object> getwxandinguserinfo(HttpServletRequest req) {
        String code = req.getParameter("code");
        //第二步:通过code获取access_token
        ConfKit confkit= new ConfKit("wxpay.properties");
		String urlwx = "https://api.weixin.qq.com/sns/jscode2session?appid="+confkit.get("appid")+"&secret="+confkit.get("appsecret")+"&js_code="+code+"&grant_type=authorization_code";
        //String urlwx = "https://api.weixin.qq.com/sns/jscode2session?appid=" + tappid + "&secret=" + tappsecret + "&js_code=" + code + "&grant_type=authorization_code";
        String access_token_json = HttpClientUtil.sendGet(urlwx);
        Map<String, String> p_access_token = JSON.parseObject(access_token_json, HashMap.class);

        Map<String, Object> setmap = new HashMap<String, Object>();
        String openid = "";
        if (p_access_token.get("openid") != null) {
            openid = p_access_token.get("openid").toString();
            Map<String, Object> wxmap = new HashMap<String, Object>();
            wxmap.put("wxid", openid);
            //查询是否已经绑定了账号和密码
            List<Map<String, Object>> list1 = wechartService.getwxuserBindStu(wxmap);
            if (list1.size() > 1) {
                setmap.put("user_type", 1);
                setmap.put("stusize", list1.size());
                List<Map<String, Object>> listmaps = new ArrayList<>();
                for (int m = 0; m < list1.size(); m++) {
                    Map<String, Object> bzh = list1.get(m);
                    Map<String, Object> struformap = new HashMap<>();
                    struformap.put("name", bzh.get("NAME"));
                    struformap.put("identity", bzh.get("ZW"));
                    struformap.put("user_type", bzh.get("WSTATE"));
                    struformap.put("nj", bzh.get("NJ"));
                    struformap.put("bj", bzh.get("BJ"));
                    struformap.put("usid", bzh.get("USID"));
                    struformap.put("dlzh", bzh.get("DLZH"));
                    struformap.put("sex", bzh.get("SEX"));
                    struformap.put("year", bzh.get("YEAR"));
                    listmaps.add(struformap);
                }
                setmap.put("stus", listmaps);
            } else if (list1.size() == 1) {
                Map<String, Object> bzh = list1.get(0);
                setmap.put("name", bzh.get("NAME"));
                setmap.put("identity", bzh.get("ZW"));
                setmap.put("user_type", bzh.get("WSTATE"));
                setmap.put("nj", bzh.get("NJ"));
                setmap.put("bj", bzh.get("BJ"));
                setmap.put("usid", bzh.get("USID"));
                setmap.put("dlzh", bzh.get("DLZH"));
                setmap.put("sex", bzh.get("SEX"));
                setmap.put("year", bzh.get("YEAR"));
            }
        }
        String session_key = p_access_token.get("session_key").toString();
        setmap.put("openid", openid);
        setmap.put("session_key", session_key);
        return setmap;
    }



    /**
     * @author 牟明艳
     * @comments 微信登录
     * @time 2019年11月23日13:43:33
     */
    @RequestMapping("wechartUaccountlogin.html")
    public @ResponseBody
    Map<String, Object> wechartUaccountlogin(HttpServletRequest req) {
        String dlzh = req.getParameter("dlzh");
        String dlma = req.getParameter("dlma");
        String wxid = req.getParameter("wxid");
        Map<String, Object> zhmap = new HashMap<String, Object>();
        zhmap.put("dlzh", dlzh);
        zhmap.put("dlma", dlma);

        //查询用户信息
        List<Map<String, Object>> list1 = new ArrayList<>();
        list1 = wechartService.getUaccountBydlzh(zhmap);

        Map<String, Object> setmap = new HashMap<String, Object>();
        if (list1.size() > 1) {
            setmap.put("user_type", 1);
            setmap.put("stusize", list1.size());
            List<Map<String, Object>> listmaps = new ArrayList<>();
            for (int m = 0; m < list1.size(); m++) {
                Map<String, Object> bzh = list1.get(m);
                Map<String, Object> struformap = new HashMap<>();
                struformap.put("name", bzh.get("NAME"));
                struformap.put("identity", bzh.get("ZW"));
                struformap.put("user_type", bzh.get("WSTATE"));
                if(bzh.get("NJ")!=null){
                    struformap.put("nj",bzh.get("NJ") );
                }
                if(bzh.get("BJ")!=null){
                    struformap.put("bj", bzh.get("BJ"));
                }
                struformap.put("usid", bzh.get("USID"));
                struformap.put("dlzh", bzh.get("DLZH"));
                struformap.put("sex", bzh.get("SEX"));
                if(bzh.get("YEAR")!=null){
                    struformap.put("year", bzh.get("YEAR"));
                }
                struformap.put("wxid",wxid);
                listmaps.add(struformap);
                //将微信ID与usid绑定
                wechartService.insertwxbangding(struformap);
            }
            setmap.put("stus", listmaps);
            setmap.put("result",true);
        } else if (list1.size() == 1) {
            Map<String, Object> bzh = list1.get(0);
            setmap.put("name", bzh.get("NAME"));
            setmap.put("identity", bzh.get("ZW"));
            setmap.put("user_type", bzh.get("WSTATE"));
            if(bzh.get("NJ")!=null){
                setmap.put("nj", bzh.get("NJ"));
            }
            if(bzh.get("BJ")!=null){
                setmap.put("bj", bzh.get("BJ"));
            }
            setmap.put("usid", bzh.get("USID"));
            setmap.put("dlzh", bzh.get("DLZH"));
            setmap.put("wxid", wxid);
            setmap.put("sex", bzh.get("SEX"));
            if(bzh.get("YEAR")!=null){
                setmap.put("year", bzh.get("YEAR"));
            }
            setmap.put("result",true);
            wechartService.insertwxbangding(setmap);
        }else{
            Map<String, Object> rmap = getthirdInfo.getUserInfoThird(dlzh, dlma);
            if (rmap.get("result").toString().equals("true")) {
                if(rmap.get("user_type").toString().equals("1")){
                    if(rmap.get("stusize").toString().equals("1")){
                        setmap.put("name", rmap.get("name"));
                        setmap.put("identity", rmap.get("identity"));
                        setmap.put("zw", rmap.get("identity"));
                        setmap.put("user_type", "1");
                        if(rmap.get("nj")!=null){
                            setmap.put("nj", rmap.get("nj"));
                        }
                        if(rmap.get("bj")!=null){
                            setmap.put("bj", rmap.get("bj"));
                        }

                        setmap.put("dlzh", dlzh);
                        setmap.put("dlma", dlma);
                        setmap.put("wxid", wxid);
                        setmap.put("sex", rmap.get("sex"));
                        if(rmap.get("year")!=null){
                            setmap.put("year", rmap.get("year"));
                        }
                        setmap.put("result",true);

                        //查询账号姓名查询该账号是否重复
                        List<Map<String,Object>>zhlist =wechartService.getStuUaccountBynamezh(setmap);
                        if(zhlist.size()>0){
                            setmap.put("usid", zhlist.get(0).get("USID"));
                            wechartService.updateUaccountByStuzh(setmap);
                        }else{
                            String usid = UUID.randomUUID().toString().replaceAll("-", "");
                            setmap.put("usid", usid);
                            setmap.put("wstate","1");
                            setmap.put("jlsczt", "0");
                            wechartService.insert_uaccount(setmap);
                        }

                    }else{
                        setmap.put("user_type", 1);
                        setmap.put("stusize", rmap.get("stusize"));
                        String stus=rmap.get("stus").toString();
                        List<Map<String,Object>> liststud = (List<Map<String,Object>>) JSONArray.parse(stus);

                        List<Map<String, Object>> listmaps = new ArrayList<>();
                        for (int m = 0; m < liststud.size(); m++) {

                            Map<String, Object> bzh = liststud.get(m);
                            Map<String, Object> struformap = new HashMap<>();
                            struformap.put("name", bzh.get("name"));
                            struformap.put("identity", bzh.get("identity"));
                            struformap.put("zw", bzh.get("identity"));
                            struformap.put("user_type","1");
                            if(bzh.get("nj")!=null){
                                struformap.put("nj",bzh.get("nj"));
                            }
                            if(bzh.get("bj")!=null){
                                struformap.put("bj", bzh.get("bj"));
                            }
                            struformap.put("dlzh", dlzh);
                            struformap.put("dlma", dlma);
                            struformap.put("sex",bzh.get("sex"));
                            struformap.put("wxid",wxid);

                            if(bzh.get("year")!=null){
                                struformap.put("year", bzh.get("year"));
                            }

                            //查询账号姓名查询该账号是否重复
                            List<Map<String,Object>>zhlist =wechartService.getStuUaccountBynamezh(struformap);
                            if(zhlist.size()>0){
                                struformap.put("usid",zhlist.get(0).get("USID"));
                                wechartService.updateUaccountByStuzh(struformap);
                            }else{
                                String usid = UUID.randomUUID().toString().replaceAll("-", "");
                                struformap.put("usid", usid);
                                struformap.put("wstate","1");
                                struformap.put("jlsczt", "0");
                                wechartService.insert_uaccount(struformap);
                            }
                            listmaps.add(struformap);

                        }
                        setmap.put("stus", listmaps);
                        setmap.put("result",true);
                    }
                }else{
                    setmap.put("name", rmap.get("name"));
                    setmap.put("identity", rmap.get("identity"));
                    setmap.put("zw", rmap.get("identity"));
                    setmap.put("user_type", "2");
                    if(rmap.get("nj")!=null){
                        setmap.put("nj", rmap.get("nj"));
                    }
                    if(rmap.get("bj")!=null){
                        setmap.put("bj", rmap.get("bj"));
                    }

                    setmap.put("dlzh", dlzh);
                    setmap.put("dlma", dlma);
                    setmap.put("wxid", wxid);
                    setmap.put("sex", rmap.get("sex"));
                    setmap.put("result",true);

                    //查询账号姓名查询该账号是否重复
                    List<Map<String,Object>>zhlist =wechartService.getStuUaccountBynamezh(setmap);
                    if(zhlist.size()>0){
                        setmap.put("usid",zhlist.get(0).get("USID"));
                        wechartService.updateUaccountByTeazh(setmap);
                    }else{
                        String usid = UUID.randomUUID().toString().replaceAll("-", "");
                        setmap.put("usid", usid);
                        setmap.put("wstate","2");
                        setmap.put("jlsczt", "0");
                        wechartService.insert_uaccount(setmap);
                    }

                }
            }else{
                return rmap;
            }
        }
        setmap.put("msg","登录成功");
        return setmap;
    }


    /**
     * 学生报名导出
     **/
    @RequestMapping("/export_sc.html")
    @ResponseBody
    public void export_sc(HttpServletRequest request, HttpServletResponse res) throws ParsePropertyException, IOException, InvalidFormatException, IllegalAccessException {

        List<Map<String, Object>> list1 = ExportExcel.downloadExcelfile();

        Map<String, Object> resultm = new HashMap<String, Object>();
        resultm.put("listdata", list1);
        /*****...................................获取数据end..............................******/
        String modalxls = "exportsc.xlsx";

        ExportExcel.download(modalxls, resultm, request, res);

        return;

    }

}
